// import com.alibaba.druid.sql.ast.SQLExpr_ptr;
// import com.alibaba.druid.sql.ast.SQLName;
// import com.alibaba.druid.sql.ast.SQLReplaceable;
// import com.alibaba.druid.sql.ast.SQLStatementImpl;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

#include "SQLShowTablesStatement.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../SQLName.h"

SQLName_ptr SQLShowTablesStatement::getDatabase()
{
  return database;
}

SQLName_ptr SQLShowTablesStatement::getFrom()
{
  return database;
}

void SQLShowTablesStatement::setDatabase(SQLName_ptr database)
{
  if (database != nullptr)
  {
    database->setParent(SharedObject(SQLShowTablesStatement));
  }

  this->database = database;
}

SQLExpr_ptr SQLShowTablesStatement::getLike()
{
  return like;
}

void SQLShowTablesStatement::setLike(SQLExpr_ptr like)
{
  if (like != nullptr)
  {
    like->setParent(SharedObject(SQLShowTablesStatement));
  }

  this->like = like;
}

BOOL_ptr SQLShowTablesStatement::isFull()
{
  return full;
}

void SQLShowTablesStatement::setFull(BOOL_ptr full)
{
  this->full = full;
}

SQLExpr_ptr SQLShowTablesStatement::getWhere()
{
  return where;
}

void SQLShowTablesStatement::setWhere(SQLExpr_ptr where)
{
  this->where = where;
}

// @Override
void SQLShowTablesStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLShowTablesStatement)))
  {
    acceptChild(visitor, database);
    acceptChild(visitor, like);
  }
  visitor->endVisit(SharedObject(SQLShowTablesStatement));
}

// @Override
BOOL_ptr SQLShowTablesStatement::replace(SQLExpr_ptr expr, SQLExpr_ptr target)
{
  if (database == expr)
  {
    setDatabase(std::dynamic_pointer_cast<SQLName>(target));
    return BOOL::TRUE;
  }

  if (like == expr)
  {
    setLike(target);
    return BOOL::TRUE;
  }

  if (where == expr)
  {
    setWhere(target);
    return BOOL::TRUE;
  }

  return BOOL::FALSE;
}

BOOL_ptr SQLShowTablesStatement::isExtended()
{
  return extended;
}

void SQLShowTablesStatement::setExtended(BOOL_ptr extended)
{
  this->extended = extended;
}
